import jieba

with open("notebook.txt", "r") as file:
    s = file.read()
    print(s)
lst = jieba.lcut(s)
print(len(lst))
set1 = set(lst)
print(len(set1))
dict1 = {}
for e in lst:
    if len(e) < 2:
        continue
    if dict1.get(e) is None:
        dict1[e] = 1
    else:
        dict1[e] = dict1.get(e) + 1
print("-" * 20)
for key, value in dict1.items():
    print(f"key={key},value={value}")

print(dict1)
print(len(dict1))

# 产生二维列表
new_list = [[key, value] for key, value in dict1.items()]
print("new_list", new_list)


def compare_func(x):
    return x[1]


# 不改变原先的列表，产生新的列表
sorted_list = sorted(new_list, key=compare_func, reverse=True)
print("new_list", new_list)
print("sorted_list", sorted_list)

# 改变原先的列表
new_list.sort(key=lambda x: x[1], reverse=True)
print("new_list", new_list)
# 首先按元组中的第一个元素升序排序，然后按第二个元素升序排序。
new_list.sort(key=lambda x: (-x[1], x[0]))
print("new_list", new_list)
# 参见： https://baijiahao.baidu.com/s?id=1776746229962957149&wfr=spider&for=pc

print(new_list[0:10])
